package cn.tedu.pet.product.controller;

import cn.tedu.pet.commons.web.JsonResult;
import cn.tedu.pet.product.pojo.param.PictureAddNewParam;
import cn.tedu.pet.product.pojo.vo.PictureListItemVO;
import cn.tedu.pet.product.service.IPictureService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 处理图片数据相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("/pictures")
@Validated
@Api(tags = "05. 图片管理模块")
public class PictureController {
    @Autowired
    private IPictureService pictureService;

    @PostMapping("/add-new")
    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid PictureAddNewParam pictureAddNewParam) {
        log.debug("开始处理【添加图片】的请求，参数：{}", pictureAddNewParam);
        pictureService.addNew(pictureAddNewParam);
        return JsonResult.ok();
    }

    @GetMapping("/list-by-album")
    @ApiOperation("根据相册ID查询图片数据列表")
    @ApiOperationSupport(order = 421)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "albumId", value = "相册ID", required = true, paramType = "query", dataType = "long")
    })
    public JsonResult<List<PictureListItemVO>> list(@Range(message = "请提交有效的相册ID值！") Long albumId) {
        log.debug("开始处理【根据相册ID查询图片数据列表】的请求，相册：{}，页码：{}", albumId);
        List<PictureListItemVO> list = pictureService.listByAlbumId(albumId);
        return JsonResult.ok(list);
    }

}
